//
//  AppDelegate.swift
//  Weibo28
//
//  Created by 高辰 on 16/5/10.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    var observer: NSObjectProtocol?
    
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
       
        
        
//        let UserAccount = GAOUserAccount.loadUserAccount()
        //监听通知,切换根控制器
       observer = NSNotificationCenter.defaultCenter().addObserverForName(SwichRootVCNotification, object: nil, queue: nil) { (notification) -> Void in
            let object = notification.object
            if object is GAOOAuthController {
            
                self.window?.rootViewController = GAOWelcomeController()
            }else {
                self.window?.rootViewController = GAOMainController()
            }
        }
        
        
        //创建Window
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        //创建根视图
        window?.rootViewController = GAOWelcomeController()
        //设置主窗口并显示
        window?.makeKeyAndVisible()
        
        SQLiteManager.manager
        return true
    }
    
    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(observer!)
        print("over")
    }

    func applicationWillResignActive(application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(application: UIApplication) {
        
        
        //清除缓存数据
        GAOStatusDAL.clearCacheData()
        
    }

    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}

